# = test.content.1.rb - Content, Edit Content Test
# 
# See LICENSE.txt for licensing details.
#
# == Description
# This will test the functionality for editing the content on the home page.
#

    require 'watir'
    include Watir
    require 'test/unit'
    require '../watir.config.rb'
    require '../resources/functions.rb'


    
    class TC_EditContentParts_test < Test::Unit::TestCase
      def startup			
        $MainContent = 'Community Server is the award winning platform for quickly and easily creating online communities and has all the integrated tools, such as: discussion forums, blogs, photo galleries, file galleries, search, RSS tools, content management, advanced user permissions required for building communities. Community Server also supports a number of add-ons and gateways that enable additional functionality such as: single sign-on modules, posting to your blog through email, the ability to post and reply to forums through email, and file management tools for easy drag-and-drop management of your file or photo gallery. You can learn more about these add-ons and others at communityserver.org.'
        @@ie = Watir::IE.start($SITE_URL)
      end
    
      def ie
        if defined? @@ie
          @@ie
        else
          startup
        end
      end
      
      def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))	
      end
      
      def test_02_verifyLoginLinksExist
        if !(ie.link(:text, 'Sign in').exists?)
          ie.goto($SITE_URL + 'logout.aspx')
          ie.refresh
          ie.goto($SITE_URL)
          ie.refresh
        end
      end
      
      def test_03_navigateToLogin
        ie.link(:text, 'Sign in').click
        assert(ie.contains_text("Sign in name"))
      end
      
      def test_04_populateLoginForm
        ie.text_field(:id, /username$/).value = $ADMIN_USER
        assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
        
        ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
        assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
      end
      
      def test_05_submitLoginForm
        ie.link(:id, /loginButton$/).click
        test_01_verifyHomeText
      end
      
      def test_06_verifyAndOpenContentPart
        test_01_verifyHomeText
        
        assert(ie.div(:id, /ctl00_ctl02$/).exists?)
        sleep 3
        ie.div(:id, /ctl00_ctl02$/).fire_event("ondblclick")
        sleep 5
      end
      
      def test_07_editContentPart  
        
          assert(ie.link(:text, 'Save').exists?)
          assert(ie.link(:text, 'Cancel').exists?)
          
          assert(ie.text_field(:id, /ctl00_Editor$/).exists?)
          ie.text_field(:id, /ctl00_Editor$/).set($MainContent)
          #ie.ie.Document.parentWindow.execScript("tinyMCE.getInstanceById(tinyMCE.getEditorId('mce_editor_0')).execCommand('mceSetContent', false, '" + $MainContent + "')")
          
          
          
          #ie.ie.Document.parentWindow.execScript("Telligent_Modal._modalIframe.contentWindow.tinyMCE.selectedInstance.execCommand('mceSetContent', false, '" + $MainContent + "')")
          
          
      
          ie.link(:text, 'Save').click

          test_01_verifyHomeText
      end
      
      def test_08_logoutTryEdit
        ie.refresh
        ie.goto($SITE_URL + "logout.aspx")
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
        
        assert_raises(UnknownObjectException) { ie.div(:id, /ctl00_ctl02$/).fire_event("ondblclick") }
       
      end
      
    end